package com.yuandianrrp.log.jdalog.utils;

import cn.hutool.core.thread.ThreadUtil;
import javafx.application.Platform;

import javax.swing.*;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @author Administrator
 */
public class SystemUtils {

    /**
     *
     */
    private static final AtomicBoolean atomicBoolean = new AtomicBoolean(true);

    /**
     * 设置值
     *
     * @param stop 是否关闭
     */
    public static void setSystemStatus(Boolean stop) {
        atomicBoolean.set(stop);
    }

    public static Boolean getSystemStatus() {
        return atomicBoolean.get();
    }

    /**
     * 系统退出
     */
    public static void exit() {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                SystemUtils.setSystemStatus(true);
                ThreadUtil.safeSleep(1000);
                System.exit(0);
            }
        });
    }
}
